package com.rede.didiok.user.service.impl;

import java.util.*;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rede.didiok.common.constant.conf.MessageConf;
import com.rede.didiok.common.constant.conf.RedisConf;
import com.rede.didiok.common.constant.conf.SQLConf;
import com.rede.didiok.common.constant.conf.SysConf;
import com.rede.didiok.common.constant.global.Constants;
import com.rede.didiok.common.domainEvent.EventAction;
import com.rede.didiok.common.dto.admin.SystemConfigDto;
import com.rede.didiok.common.dto.community.MomentCommentDto;
import com.rede.didiok.common.dto.community.UserMomentDto;
import com.rede.didiok.common.dto.pay.PayOrderDto;
import com.rede.didiok.common.dto.rank.MemberCommentDto;
import com.rede.didiok.common.dto.rank.RankMemberDto;
import com.rede.didiok.common.dto.user.NoticeDto;
import com.rede.didiok.common.enums.*;
import com.rede.didiok.common.exception.exceptionType.FeignException;
import com.rede.didiok.common.exception.exceptionType.InsertException;
import com.rede.didiok.common.exception.exceptionType.QueryException;
import com.rede.didiok.common.feign.AdminFeignClient;
import com.rede.didiok.common.feign.CommunityFeignClient;
import com.rede.didiok.common.feign.RankFeignClient;
import com.rede.didiok.common.holder.RequestHolder;
import com.rede.didiok.common.utils.*;
import com.rede.didiok.common.utils.admin.SystemConfigUtil;
import com.rede.didiok.common.utils.business.DomainEventUtil;
import com.rede.didiok.common.utils.business.RabbitMqUtil;
import com.rede.didiok.user.dao.NoticeDao;
import com.rede.didiok.user.entity.NoticeEntity;
import com.rede.didiok.user.entity.UserEntity;
import com.rede.didiok.user.entity.UserWatchEntity;
import com.rede.didiok.user.modulelist.rank.dao.RankMemberDao;
import com.rede.didiok.user.modulelist.rank.entity.RankMemberEntity;
import com.rede.didiok.user.service.NoticeService;
import com.rede.didiok.user.service.UserService;
import com.rede.didiok.user.service.UserWatchService;


@Service("noticeService")
public class NoticeServiceImpl extends ServiceImpl<NoticeDao, NoticeEntity> implements NoticeService {


    @Autowired
    private RedisUtil redisUtil;

    @Resource
    private UserWatchService userWatchService;

    @Resource
    private RankFeignClient rankFeignClient;

    @Resource
    private CommunityFeignClient communityFeignClient;

    @Resource
    private UserService userService;

    @Resource
    private RankMemberDao rankMemberDao;

//    @Resource
//    private CollectService collectService;
    @Resource
    private DomainEventUtil domainEventUtil;
    @Value(value = "${data.website.url}")
    private String dataWebsiteUrl;
    @Resource
    private RabbitMqUtil rabbitMqUtil;
    @Resource
    private AdminFeignClient adminFeignClient;
    @Resource
    private SystemConfigUtil systemConfigUtil;

    /***************************** admin:start **************************/
    // region  didiok-admin

    @Override
    public IPage<NoticeEntity> getPageList(NoticeDto noticeDto) {
        QueryWrapper<NoticeEntity> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(noticeDto.getCreateUserUid())) {
            queryWrapper.eq(SQLConf.CREATE_USER_UID, noticeDto.getCreateUserUid());
        }
        if (noticeDto.getIsBack() != null) {
            queryWrapper.eq(SQLConf.IS_BACK, noticeDto.getIsBack());
        }
        if (noticeDto.getNoticeType() == 0) {
            throw new QueryException("通知类型不能为空");
        } else {
            queryWrapper.eq(SQLConf.NOTICE_TYPE, noticeDto.getNoticeType());
        }
        Page<NoticeEntity> page = new Page<>();
        page.setSize(noticeDto.getPageSize());
        page.setCurrent(noticeDto.getCurrentPage());
        queryWrapper.eq(SQLConf.STATUS, StatusEnum.ENABLE);
        queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
        IPage<NoticeEntity> noticeIPage = this.page(page, queryWrapper);
        noticeIPage.setRecords(convertNoticeList(noticeIPage.getRecords()));
        return noticeIPage;
    }

    @Override
    public String addNotice(NoticeDto noticeDto) {
        NoticeEntity notice = new NoticeEntity();
        // 使用Spring工具类提供的深拷贝
        BeanUtils.copyProperties(noticeDto, notice, SysConf.STATUS);
        boolean isSave = notice.insert();
        //如果是后台站内信  不需要更新收件箱
        if (Objects.equals(notice.getIsBack(), 0)) {
            // 同时更新他的收件箱
            this.sendNoticeByRedis(notice);
        }
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);
    }

    @Override
    public String editNotice(NoticeDto noticeDto) {

        NoticeEntity notice = this.getById(noticeDto.getUid());
        if (notice == null) {
            return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
        }
        BeanUtils.copyProperties(noticeDto, notice, SysConf.STATUS, SysConf.UID);
        notice.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
    }

    @Override
    public String deleteNotice(NoticeDto noticeDto) {
        List<NoticeDto> noticeVOList = new ArrayList<>();
        noticeVOList.add(noticeDto);
        return this.deleteBatchNotice(noticeVOList);
    }

    @Override
    public String deleteBatchNotice(List<NoticeDto> noticeVOList) {
        Set<String> noticeUidList = new HashSet<>();
        noticeVOList.forEach(item -> {
            noticeUidList.add(item.getUid());
        });

        if (noticeUidList.size() < 0) {
            return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
        }

        Collection<NoticeEntity> noticeList = this.listByIds(noticeUidList);

        String userUid = RequestHolder.getUserUid();
        if (StringUtils.isEmpty(userUid)) {
            throw new QueryException(Constants.USER_UID_EMPTY);
        }
        noticeList.forEach(item -> {
            if (userUid != null && !userUid.equals(item.getCreateUserUid())) {
                throw new QueryException("无法删除别人的通知");
            }
            item.setStatus(StatusEnum.DISABLED);
            // 删除通知事件
            domainEventUtil.publishEvent(EventAction.NOTICE_DELETE, item);
        });
        this.updateBatchById(noticeList);
        return ResultUtil.successWithMessage(MessageConf.DELETE_SUCCESS);
    }

    /**
     * 获取后台站内信列表
     *
     * @return
     */
    public IPage<NoticeEntity> getBackNoticeList(NoticeDto noticeDto) {
        String adminUid = RequestHolder.getAdminUid();
        QueryWrapper<NoticeEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(SQLConf.IS_BACK, StatusEnum.ENABLE);
        wrapper.eq(SQLConf.STATUS, StatusEnum.ENABLE);
        wrapper.eq(SQLConf.ADMINUID, adminUid);
        wrapper.orderByDesc(SQLConf.CREATE_TIME);
        Page<NoticeEntity> page = new Page<>();
        page.setCurrent(noticeDto.getCurrentPage());
        page.setSize(noticeDto.getPageSize());
        IPage<NoticeEntity> pageList = this.page(page, wrapper);
        List<String> userUidList = new ArrayList<>();
        pageList.getRecords().forEach((notice) -> {
            userUidList.add(notice.getCreateUserUid());
        });
        // 获取带用户头像的
        Map<String, UserEntity> userMap = userService.getUserAvatarMapByIds(userUidList);

        //将 businessTypeName 设置进去
        pageList.getRecords().forEach((notice) -> {
            BusinessTypeEnum businessType = BusinessTypeEnum.getType(String.valueOf(notice.getBusinessType()));
            if (businessType != null) {
                notice.setBusinessTypeName(businessType.getName());
            }
            if (StringUtils.isNotEmpty(notice.getCreateUserUid())) {
                notice.setUser(userMap.get(notice.getCreateUserUid()));
            }

        });
        return pageList;
    }

    /**
     * 删除当前管理员小红点通知
     *
     * @return
     */
    public void deleteRedisBatchNotice(String adminUid) {
        String redisKey = RedisConf.ADMIN_NOTICE_POINT + Constants.SYMBOL_COLON + adminUid;
        //如果key存在， 则删除该key
        Boolean hasKey = redisUtil.hasKey(redisKey);
        if (hasKey) {
            redisUtil.delete(redisKey);
        }
    }

    /**
     * @param adminUid
     */
    public Integer searchAllNoticeCount(String adminUid) {
        String redisKey = RedisConf.ADMIN_NOTICE_POINT + Constants.SYMBOL_COLON + adminUid;
        //如果key存在， 则删除该key
        Boolean hasKey = redisUtil.hasKey(redisKey);
        if (hasKey) {
            String s = redisUtil.get(redisKey);
            return Integer.parseInt(s);
        } else {
            return 0;
        }
    }

    // endregion
    /***************************** admin:end **************************/



    /***************************** web:start **************************/
    // region didiok-web

    @Override
    public String getUserReceiveNoticeCount() {
        HttpServletRequest request = RequestHolder.getRequest();
        int receiveNoticeMemberCommentCount = 0;
        int receiveNoticeMomentCommentCount = 0;
        int receiveNoticeWatchCount = 0;
        int receiveNoticePraiseCount = 0;
        int receiveNoticeSystemCount = 0;
        int receiveNoticeCollectCount = 0;
        int receiveNoticeMessageCount = 0;
        int receiveNoticeMessageGroupCount = 0;
        // 活动报名
        int receiveOrderCount = 0;

        if (request.getAttribute(SysConf.USER_UID) != null) {
            String userUid = request.getAttribute(SysConf.USER_UID).toString();

            String memberCommentCount = redisUtil.get(RedisConf.USER_RECEIVE_MEMBER_COMMENT_COUNT + Constants.SYMBOL_COLON + userUid);
            String momentCommentCount = redisUtil.get(RedisConf.USER_RECEIVE_MOMENT_COMMENT_COUNT + Constants.SYMBOL_COLON + userUid);
            String watchCount = redisUtil.get(RedisConf.USER_RECEIVE_WATCH_COUNT + Constants.SYMBOL_COLON + userUid);
            String praiseCount = redisUtil.get(RedisConf.USER_RECEIVE_PRAISE_COUNT + Constants.SYMBOL_COLON + userUid);
            String systemCount = redisUtil.get(RedisConf.USER_RECEIVE_SYSTEM_NOTICE_COUNT + Constants.SYMBOL_COLON + userUid);
            String messageCount = redisUtil.get(RedisConf.USER_RECEIVE_MESSAGE_COUNT + Constants.SYMBOL_COLON + userUid);
            String collectCount = redisUtil.get(RedisConf.USER_RECEIVE_COLLECT_COUNT + Constants.SYMBOL_COLON + userUid);

            String userMessageGroupCount = redisUtil.get(RedisConf.USER_RECEIVE_GROUP_MESSAGE_COUNT + Constants.SYMBOL_COLON + userUid);
            String messageGroupCount = redisUtil.get(RedisConf.USER_RECEIVE_GROUP_MESSAGE_COUNT);
            // 活动报名
            String orderCount = redisUtil.get(RedisConf.USER_RECEIVE_ORDER_COUNT);

            if (StringUtils.isNotEmpty(memberCommentCount)) {
                receiveNoticeMemberCommentCount = Integer.parseInt(memberCommentCount);
            }
            if (StringUtils.isNotEmpty(momentCommentCount)) {
                receiveNoticeMomentCommentCount = Integer.parseInt(momentCommentCount);
            }
            if (StringUtils.isNotEmpty(watchCount)) {
                receiveNoticeWatchCount = Integer.parseInt(watchCount);
            }
            if (StringUtils.isNotEmpty(praiseCount)) {
                receiveNoticePraiseCount = Integer.parseInt(praiseCount);
            }
            if (StringUtils.isNotEmpty(systemCount)) {
                receiveNoticeSystemCount = Integer.parseInt(systemCount);
            }
            if (StringUtils.isNotEmpty(collectCount)) {
                receiveNoticeCollectCount = Integer.parseInt(collectCount);
            }
            if (StringUtils.isNotEmpty(messageCount)) {
                receiveNoticeMessageCount = Integer.parseInt(messageCount);
            }
            if (StringUtils.isNotEmpty(messageCount)) {
                receiveNoticeMessageCount = Integer.parseInt(messageCount);
            }

            // 为空，说明用户没有点击过通知
            if (StringUtils.isEmpty(userMessageGroupCount)) {
                // 判断群组有没有接收过通知
                if (StringUtils.isNotEmpty(messageGroupCount)) {
                    receiveNoticeMessageGroupCount = Integer.parseInt(messageGroupCount);
                }
            }
            // 活动报名
            if (StringUtils.isNotEmpty(orderCount)) {
                receiveOrderCount = Integer.parseInt(orderCount);
            }
        }

        Map<String, Integer> map = new HashMap<>(Constants.NUM_FOUR);
        map.put(SysConf.USER_RECEIVE_MEMBER_COMMENT_COUNT, receiveNoticeMemberCommentCount);
        map.put(SysConf.USER_RECEIVE_MOMENT_COMMENT_COUNT, receiveNoticeMomentCommentCount);
        map.put(SysConf.USER_RECEIVE_WATCH_COUNT, receiveNoticeWatchCount);
        map.put(SysConf.USER_RECEIVE_PRAISE_COUNT, receiveNoticePraiseCount);
        map.put(SysConf.USER_RECEIVE_SYSTEM_NOTICE_COUNT, receiveNoticeSystemCount);
        map.put(SysConf.USER_RECEIVE_COLLECT_COUNT, receiveNoticeCollectCount);
        map.put(SysConf.USER_RECEIVE_MESSAGE_COUNT, receiveNoticeMessageCount + receiveNoticeMessageGroupCount);

        // 活动报名
        map.put(SysConf.USER_RECEIVE_ORDER_COUNT, receiveOrderCount);

        return ResultUtil.successWithData(map);
    }

    @Override
    public String readUserReceiveNoticeCount() {
        HttpServletRequest request = RequestHolder.getRequest();
        String userUid = request.getAttribute(SysConf.USER_UID).toString();
        redisUtil.delete(RedisConf.USER_RECEIVE_MEMBER_COMMENT_COUNT + Constants.SYMBOL_COLON + userUid);
        redisUtil.delete(RedisConf.USER_RECEIVE_MOMENT_COMMENT_COUNT + Constants.SYMBOL_COLON + userUid);
        redisUtil.delete(RedisConf.USER_RECEIVE_WATCH_COUNT + Constants.SYMBOL_COLON + userUid);
        redisUtil.delete(RedisConf.USER_RECEIVE_PRAISE_COUNT + Constants.SYMBOL_COLON + userUid);
        redisUtil.delete(RedisConf.USER_RECEIVE_SYSTEM_NOTICE_COUNT + Constants.SYMBOL_COLON + userUid);
        redisUtil.delete(RedisConf.USER_RECEIVE_MESSAGE_COUNT + Constants.SYMBOL_COLON + userUid);
        redisUtil.delete(RedisConf.USER_RECEIVE_COLLECT_COUNT + Constants.SYMBOL_COLON + userUid);
        redisUtil.delete(RedisConf.USER_RECEIVE_ORDER_COUNT + Constants.SYMBOL_COLON + userUid);
        // 阅读过群组消息，往redis插入记录
        redisUtil.setEx(RedisConf.USER_RECEIVE_GROUP_MESSAGE_COUNT + Constants.SYMBOL_COLON + userUid, Constants.STR_ONE, 7, TimeUnit.DAYS);
        // 发送阅读通知事件
        domainEventUtil.publishEvent(EventAction.NOTICE_VIEW, new NoticeEntity());
        return ResultUtil.successWithMessage("阅读成功");
    }

    @Override
    public String readNoticeByType(NoticeDto noticeDto) {
        String readNoticeType = noticeDto.getReadNoticeType();
        HttpServletRequest request = RequestHolder.getRequest();
        String userUid = request.getAttribute(SysConf.USER_UID).toString();
        redisUtil.delete(readNoticeType + Constants.SYMBOL_COLON + userUid);
        if(RedisConf.USER_RECEIVE_GROUP_MESSAGE_COUNT.equals(readNoticeType)) {
            // 阅读过群组消息，往redis插入记录
            redisUtil.setEx(RedisConf.USER_RECEIVE_GROUP_MESSAGE_COUNT + Constants.SYMBOL_COLON + userUid, Constants.STR_ONE, 7, TimeUnit.DAYS);
        }
        // 发送阅读通知事件
        domainEventUtil.publishEvent(EventAction.NOTICE_VIEW, new NoticeEntity());
        return ResultUtil.successWithMessage("阅读成功");
    }


    // endregion
    /***************************** web:end **************************/

    /**
     * 通过redis发送通知（小红点）
     *
     * @param notice
     */
    private void sendNoticeByRedis(NoticeEntity notice) {
        // 同时更新他的收件箱
        // 如果用户发送的内容，需要向该用户Redis收件箱中中写入一条记录
        String userUid = notice.getCreateUserUid();
        String redisKey = "";
        switch (NoticeTypeEnum.getNoticeType(notice.getNoticeType())) {
            case MEMBER_COMMENT: {
                redisKey = RedisConf.USER_RECEIVE_MEMBER_COMMENT_COUNT + Constants.SYMBOL_COLON + userUid;
            }
            break;
            case MOMENT_COMMENT: {
                redisKey = RedisConf.USER_RECEIVE_MOMENT_COMMENT_COUNT + Constants.SYMBOL_COLON + userUid;
            }
            break;
            case WATCH: {
                redisKey = RedisConf.USER_RECEIVE_WATCH_COUNT + Constants.SYMBOL_COLON + userUid;
            }
            break;
            case PRAISE: {
                redisKey = RedisConf.USER_RECEIVE_PRAISE_COUNT + Constants.SYMBOL_COLON + userUid;
            }
            break;
            case COLLECT: {
                redisKey = RedisConf.USER_RECEIVE_COLLECT_COUNT + Constants.SYMBOL_COLON + userUid;
            }
            break;
            case SYSTEM: {
                redisKey = RedisConf.USER_RECEIVE_SYSTEM_NOTICE_COUNT + Constants.SYMBOL_COLON + userUid;
            }
            break;
            case ORDER_NOTICE: {
                redisKey = RedisConf.USER_RECEIVE_ORDER_COUNT + Constants.SYMBOL_COLON + userUid;
            }
            break;
            default:
                throw new InsertException("通知类型转换异常");
        }
        // 消息红点保留7天
        String count = redisUtil.get(redisKey);
        if (StringUtils.isNotEmpty(count)) {
            redisUtil.incrBy(redisKey, Constants.NUM_ONE);
        } else {
            redisUtil.setEx(redisKey, Constants.STR_ONE, 7, TimeUnit.DAYS);
        }
    }

    /**
     * 转换通知列表
     * TODO 这一堆代码属实有些难看，后面再重构把
     *
     * @param noticeList
     * @return
     */
    public List<NoticeEntity> convertNoticeList(List<NoticeEntity> noticeList) {
        if (noticeList.size() == 0) {
            return noticeList;
        }
//        Set<String> memberCommentUidSet = new HashSet<>();
//        Set<String> momentCommentUidSet = new HashSet<>();
////        Set<String> watchUidSet = new HashSet<>();
//        Set<String> blogUidSet = new HashSet<>();
////        Set<String> questionUidSet = new HashSet<>();
//        Set<String> momentUidSet = new HashSet<>();
////        Set<String> praiseUidSet = new HashSet<>();
////        Set<String> collectUidSet = new HashSet<>();
        Set<String> userUidSet = new HashSet<>();
//        Set<String> orderUidSet = new HashSet<>();

        for (NoticeEntity item : noticeList) {
            if (StringUtils.isNotEmpty(item.getFromUserUid())) {
                userUidSet.add(item.getFromUserUid());
            }
//            if (BusinessTypeEnum.RANK_MEMBER.getCode().equals(item.getBusinessType())) {
//                blogUidSet.add(item.getBusinessUid());
//            } else if (BusinessTypeEnum.MOMENT.getCode().equals(item.getBusinessType())) {
//                momentUidSet.add(item.getBusinessUid());
//            } else if (NoticeTypeEnum.MEMBER_COMMENT.getCode().equals(item.getNoticeType())) {
//                memberCommentUidSet.add(item.getBusinessUid());
//            }else if (NoticeTypeEnum.MOMENT_COMMENT.getCode().equals(item.getNoticeType())) {
//                momentCommentUidSet.add(item.getBusinessUid());
//            }else if (NoticeTypeEnum.ORDER_NOTICE.getCode().equals(item.getNoticeType())) {
//                orderUidSet.add(item.getBusinessUid());
//            }


//            else if (BusinessTypeEnum.USER_WATCH.getCode().equals(item.getNoticeType())) {
//                watchUidSet.add(item.getBusinessUid());
//            }

//            else if (BusinessTypeEnum.PRAISE.getCode().equals(item.getNoticeType())) {
//                praiseUidSet.add(item.getBusinessUid());
//            } else if (BusinessTypeEnum.COLLECT.getCode().equals(item.getNoticeType())) {
//                collectUidSet.add(item.getBusinessUid());
//            }
        }
//
//        // 从点赞表中，获取到点赞的资源
//        Map<String, UserPraiseRecord> userPraiseRecordMap = new HashMap<>();
//        if (praiseUidSet.size() > 0) {
//            Collection<UserPraiseRecord> userPraiseRecordCollection = userPraiseRecordService.listByIds(praiseUidSet);
//            userPraiseRecordCollection.forEach(item -> {
//                // 设置点赞人的信息
//                userUidSet.add(item.getUserUid());
//                // 将点赞信息存储
//                userPraiseRecordMap.put(item.getUid(), item);
//                if (EResourceType.BLOG.getType().equals(item.getResourceType())) {
//                    blogUidSet.add(item.getResourceUid());
//                } else if (EResourceType.Question.getType().equals(item.getResourceType())) {
//                    questionUidSet.add(item.getResourceUid());
//                } else if (EResourceType.MOMENT.getType().equals(item.getResourceType())) {
//                    momentUidSet.add(item.getResourceUid());
//                } else if (EResourceType.COMMENT.getType().equals(item.getResourceType())) {
//                    commentUidSet.add(item.getResourceUid());
//                } else if (EResourceType.PROBLEM.getType().equals(item.getResourceType())) {
//                    problemUidSet.add(item.getResourceUid());
//                }
//            });
//        }
//
//        // 从收藏表中，获取到收藏的资源
//        Map<String, Collect> collectMap = new HashMap<>();
//        if (collectUidSet.size() > 0) {
//            Collection<Collect> collectCollection = collectService.listByIds(collectUidSet);
//            for (Collect item : collectCollection) {
//                // 设置点赞人的信息
//                userUidSet.add(item.getUserUid());
//                // 将点赞信息存储
//                collectMap.put(item.getUid(), item);
//                if (EResourceType.BLOG.getType().equals(item.getCollectType())) {
//                    blogUidSet.add(item.getBizUid());
//                } else if (EResourceType.Question.getType().equals(item.getCollectType())) {
//                    questionUidSet.add(item.getBizUid());
//                } else if (EResourceType.MOMENT.getType().equals(item.getCollectType())) {
//                    momentUidSet.add(item.getBizUid());
//                } else if (EResourceType.COMMENT.getType().equals(item.getCollectType())) {
//                    commentUidSet.add(item.getBizUid());
//                } else if (EResourceType.PROBLEM.getType().equals(item.getCollectType())) {
//                    problemUidSet.add(item.getBizUid());
//                }
//            }
//        }

//        List<MemberCommentDto> memberCommentList = new ArrayList<>();
//        Map<String, MemberCommentDto> memberCommentMap = new HashMap<>();
//        if (memberCommentUidSet.size() > 0) {
//            String jsonStr = rankFeignClient.getCommentPageListByIds(memberCommentUidSet);
//            Map<String, Object> dataMap = (Map<String, Object>) JsonUtils.jsonToObject(jsonStr, Map.class);
//            if (BaseSysConf.SUCCESS.equals(dataMap.get(BaseSysConf.CODE))) {
//                String jsonList = JsonUtils.objectToJson(dataMap.get(BaseSysConf.DATA));
//                memberCommentList = JSONArray.parseArray(jsonList, MemberCommentDto.class);
//            }
//            memberCommentList.forEach(item -> {
//                memberCommentMap.put(item.getUid(), item);
//            });
//        }
//        List<MomentCommentDto> momentCommentList = new ArrayList<>();
//        Map<String, MomentCommentDto> momentCommentMap = new HashMap<>();
//        if (momentCommentUidSet.size() > 0) {
//            String jsonStr = communityFeignClient.getCommentPageListByIds(momentCommentUidSet);
//            Map<String, Object> dataMap = (Map<String, Object>) JsonUtils.jsonToObject(jsonStr, Map.class);
//            if (BaseSysConf.SUCCESS.equals(dataMap.get(BaseSysConf.CODE))) {
//                String jsonList = JsonUtils.objectToJson(dataMap.get(BaseSysConf.DATA));
//                momentCommentList = JSONArray.parseArray(jsonList, MomentCommentDto.class);
//            }
//            momentCommentList.forEach(item -> {
//                momentCommentMap.put(item.getUid(), item);
//            });
//        }

//        Map<String, RankMemberDto> rankMemberMap = new HashMap<>();
//        if (blogUidSet.size() > 0) {
//            List<String> memberUidList = blogUidSet.stream().collect(Collectors.toList());
//            R result = rankFeignClient.listRankMemberByUidList(memberUidList);
//            if(result.getCode() == 0) {
//                List<RankMemberDto> blogCollection = result.getData(new TypeReference<List<RankMemberDto>>() {
//                });
//
//
//                blogCollection.forEach(item -> {
//                    if (StringUtils.isNotEmpty(item.getCreateUserUid())) {
//                        userUidSet.add(item.getCreateUserUid());
//                    }
//                    rankMemberMap.put(item.getUid(), item);
//                });
//            }else {
//                throw new FeignException("feign调用异常（根据uid列表查询榜单成员）：失败");
//            }
//        }

//        List<UserWatchEntity> userWatchList = new ArrayList<>();
//        Map<String, UserWatchEntity> userWatchMap = new HashMap<>();
//
//        if (watchUidSet.size() > 0) {
//            Collection<UserWatchEntity> userWatchCollection = userWatchService.listByIds(watchUidSet);
//            userWatchList = userWatchService.convertUserWatchList(userWatchCollection);
//            userWatchList.forEach(item -> {
//                userWatchMap.put(item.getUid(), item);
//            });
//        }

//        Map<String, UserMomentDto> momentMap = new HashMap<>();
//        if (momentUidSet.size() > 0) {
//            List<String> momentUidList = momentUidSet.stream().collect(Collectors.toList());
//            R result = communityFeignClient.listUserMomentByUidList(momentUidList);
//            List<UserMomentDto> momentList;
//            if (result.getCode() == 0) {
//                momentList = result.getData(new TypeReference<List<UserMomentDto>>() {
//                });
//            }else {
//                throw new FeignException("feign调用异常（根据id集合查询用户动态）：失败");
//            }
//            momentList.forEach(item -> {
//                if (StringUtils.isNotEmpty(item.getCreateUserUid())) {
//                    userUidSet.add(item.getCreateUserUid());
//                }
//                momentMap.put(item.getUid(), item);
//            });
//        }

        // 设置用户
        Map<String, UserEntity> userMap = new HashMap<>();
        if (userUidSet.size() > 0) {
            Collection<UserEntity> userCollection = userService.listByIds(userUidSet);
            List<UserEntity> userList = userService.convertUserList(userCollection);
            userService.setUserAvatar(userList);
            userList.forEach(item -> {
                userMap.put(item.getUid(), item);
            });
        }

        noticeList.forEach(item -> {
            if (StringUtils.isNotEmpty(item.getFromUserUid())) {
                UserEntity user = userMap.get(item.getFromUserUid());
                item.setFromUser(user);
            }
//            // 评论动作
//            if (NoticeTypeEnum.MEMBER_COMMENT.getCode().equals(item.getNoticeType())) {
//                item.setMemberComment(memberCommentMap.get(item.getBusinessUid()));
//
//                // 评论动作
//            }else if (NoticeTypeEnum.MOMENT_COMMENT.getCode().equals(item.getNoticeType())) {
//                item.setMomentComment(momentCommentMap.get(item.getBusinessUid()));
//
//            }
////            else if (NoticeTypeEnum.WATCH.getCode().equals(item.getNoticeType())) {
////                item.setUserWatch(userWatchMap.get(item.getBusinessUid()));
////            }
//            else if (NoticeTypeEnum.SYSTEM.getCode().equals(item.getNoticeType())) {
//                if (BusinessTypeEnum.RANK_MEMBER.getCode().equals(item.getBusinessType())) {
//                    RankMemberDto memberDto = rankMemberMap.get(item.getBusinessUid());
//                    if (memberDto != null) {
//                        if (memberDto.getCreateUserUid() != null) {
//                            UserEntity user = userMap.get(memberDto.getCreateUserUid());
//                            UserDto userDto = new UserDto();
//                            BeanUtils.copyProperties(user,userDto);
//                            memberDto.setUser(userDto);
//                        }
//                        // 移除文章内容
//                        memberDto.setContent("");
//                        item.setRankMember(memberDto);
//                    }
//                } else if (BusinessTypeEnum.MOMENT.getCode().equals(item.getBusinessType())) {
//                    UserMomentDto userMoment = momentMap.get(item.getBusinessUid());
//                    if (userMoment != null) {
//                        if (userMoment.getCreateUserUid() != null) {
//                            UserEntity user = userMap.get(userMoment.getCreateUserUid());
//                            UserDto userDto = new UserDto();
//                            BeanUtils.copyProperties(user,userDto);
//                            userMoment.setUser(userDto);
//                        }
//                        item.setUserMoment(userMoment);
//                    }
//                }
//            }
        });
        return noticeList;
    }

    @Override
    public String batchAddNoticeByWatch(NoticeDto noticeVO) {
        // 判断是否有人关注过该作者, 需要想关注作者的人，推送系统通知，告知博客更新
        QueryWrapper<UserWatchEntity> queryWrapper = new QueryWrapper();
        queryWrapper.eq(SQLConf.STATUS, StatusEnum.ENABLE);
        if (StringUtils.isNotEmpty(noticeVO.getAdminUid())) {
            queryWrapper.eq(SQLConf.TO_USER_UID, noticeVO.getAdminUid());
        } else if (StringUtils.isNotEmpty(noticeVO.getCreateUserUid())) {
            queryWrapper.eq(SQLConf.TO_USER_UID, noticeVO.getCreateUserUid());
        } else {
            throw new InsertException("插入失败，消息通知发送失败");
        }

        List<UserWatchEntity> userWatchList = userWatchService.list(queryWrapper);
        List<NoticeEntity> noticeList = new ArrayList<>();
        userWatchList.forEach(item -> {
            String userUid = item.getCreateUserUid();
            NoticeEntity notice = new NoticeEntity();
            notice.setCreateUserUid(userUid);
            notice.setNoticeType(NoticeTypeEnum.SYSTEM.getCode());
            notice.setBusinessType(noticeVO.getBusinessType());
            notice.setBusinessUid(noticeVO.getBusinessUid());
            notice.setNoticeType(noticeVO.getNoticeType());
            notice.setStatus(StatusEnum.ENABLE);
            noticeList.add(notice);
            // 同时更新他的收件箱
            this.sendNoticeByRedis(notice);
        });

        if (noticeList.size() > 0) {
            this.saveBatch(noticeList);
        }
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);
    }

    @Override
    public boolean sendNoticeByMemberComment(MemberCommentDto comment) {

        if (StringUtils.isEmpty(comment.getToUid())) {
            // 当该评论是一级评论的时候，说明是对 博客详情、留言板、关于我
            // 判断是否开启邮件通知【管理员邮箱通知】
            SystemConfigDto systemConfig = systemConfigUtil.getSystemConfig();
            if (systemConfig != null && OpenStatusEnum.OPEN.equals(systemConfig.getStartEmailNotification())) {
                if (StringUtils.isNotEmpty(systemConfig.getEmail())) {
                    String sourceName = CommentSourceEnum.valueOf(comment.getSource()).getName();
                    String linkText = "<a href=\" " + getUrlByMemberCommentSource(comment) + "\">" + sourceName + "</a>\n";
                    String commentContent = linkText + "收到新的评论: " + comment.getContent();
                    rabbitMqUtil.sendSimpleEmail(systemConfig.getEmail(), commentContent);
                } else {
                    log.error("网站没有配置通知接收的邮箱地址！");
                }
            }
        }

        // 判断被评论的用户，是否开启了评论邮件提醒
        if (StringUtils.isNotEmpty(comment.getToUserUid())) {
            UserEntity toUser = userService.getById(comment.getToUserUid());
            if (toUser.getStartEmailNotification() == SysConf.ONE) {
                R memberCommentResult = rankFeignClient.getCommentById(comment.getToUid());
                MemberCommentDto toComment;
                if (memberCommentResult.getCode() == 0) {
                    toComment = memberCommentResult.getData(new TypeReference<MemberCommentDto>(){});
                }else {
                    throw new FeignException("feign调用异常（根据id获取榜单成员评论）：失败");
                }
                sendEmailByMemberComment(comment, toUser, toComment);
            }
            // 向该用户推送消息通知
            NoticeEntity notice = new NoticeEntity();
            notice.setCreateUserUid(comment.getToUserUid());
            notice.setNoticeType(NoticeTypeEnum.MEMBER_COMMENT.getCode());
            // 设置通知类型
            if (CommentSourceEnum.RANK_MEMBER_INFO.getCode().equals(comment.getSource())) {
                notice.setBusinessType(BusinessTypeEnum.RANK_MEMBER_REPLY.getCode());
            } else if (CommentSourceEnum.ABOUT.getCode().equals(comment.getSource())) {
                notice.setBusinessType(BusinessTypeEnum.ABOUT_ME_REPLY.getCode());
            } else if (CommentSourceEnum.MESSAGE_BOARD.getCode().equals(comment.getSource())) {
                notice.setBusinessType(BusinessTypeEnum.MESSAGE_BOARD_REPLY.getCode());
            } else if (CommentSourceEnum.USER_MOMENT.getCode().equals(comment.getSource())) {
                notice.setBusinessType(BusinessTypeEnum.USER_MOMENT_REPLY.getCode());
            }  else {
                throw new InsertException("消息发送失败，输入错误的评论类型");
            }
//            notice.setBusinessUid(comment.getUid());
            // 业务id改成活动id
            notice.setBusinessUid(comment.getMemberUid());
            notice.insert();

            // 被评论的人，收到小红点通知
            String redisKey = RedisConf.USER_RECEIVE_MEMBER_COMMENT_COUNT + Constants.SYMBOL_COLON + comment.getToUserUid();
            String count = redisUtil.get(redisKey);
            if (StringUtils.isNotEmpty(count)) {
                redisUtil.incrBy(redisKey, Constants.NUM_ONE);
            } else {
                redisUtil.setEx(redisKey, Constants.STR_ONE, 7, TimeUnit.DAYS);
            }

        } else {
            String tempUserUid = "";
            // 如果是一级评论，需要判断该文章或者问答是否属于用户投稿的
            if (CommentSourceEnum.RANK_MEMBER_INFO.getCode().equals(comment.getSource())) {
                R memberResult = rankFeignClient.getRankMemberById(comment.getMemberUid());
                RankMemberDto rankMemberDto;
                if (memberResult.getCode() == 0) {
                    rankMemberDto = memberResult.getData(new TypeReference<RankMemberDto>(){});
                }else {
                    throw new FeignException("feign调用异常（根据id获取榜单成员）：失败");
                }
                if (rankMemberDto != null && ContributeSourceEnum.USER_PUBLISH.equals(rankMemberDto.getRankMemberSource())) {
                    tempUserUid = rankMemberDto.getCreateUserUid();
                    // 当是门户投稿添加的，需要向号主发送评论通知
                    NoticeEntity notice = new NoticeEntity();
                    notice.setCreateUserUid(tempUserUid);
                    notice.setFromUserUid(comment.getCreateUserUid());
                    notice.setNoticeType(NoticeTypeEnum.MEMBER_COMMENT.getCode());
                    notice.setBusinessType(BusinessTypeEnum.RANK_MEMBER_COMMENT.getCode());
//                    notice.setBusinessUid(comment.getUid());
                    // 业务id改成活动id
                    notice.setBusinessUid(comment.getMemberUid());
                    notice.insert();
                }
            }

            // 如果用户投稿的文章收到评论，需要向该用户Redis收件箱中中写入一条记录
            if (StringUtils.isNotEmpty(tempUserUid)) {
                String redisKey = RedisConf.USER_RECEIVE_MEMBER_COMMENT_COUNT + Constants.SYMBOL_COLON + tempUserUid;
                String count = redisUtil.get(redisKey);
                if (StringUtils.isNotEmpty(count)) {
                    redisUtil.incrBy(redisKey, Constants.NUM_ONE);
                } else {
                    redisUtil.setEx(redisKey, Constants.STR_ONE, 7, TimeUnit.DAYS);
                }
            }
        }
        return true;
    }

    @Override
    public boolean sendNoticeByMomentComment(MomentCommentDto comment) {

        if (StringUtils.isEmpty(comment.getToUid())) {
            // 当该评论是一级评论的时候，说明是对 博客详情、留言板、关于我
            // 判断是否开启邮件通知【管理员邮箱通知】
            SystemConfigDto systemConfig = systemConfigUtil.getSystemConfig();
            if (systemConfig != null && OpenStatusEnum.OPEN.equals(systemConfig.getStartEmailNotification())) {
                if (StringUtils.isNotEmpty(systemConfig.getEmail())) {
                    String sourceName = CommentSourceEnum.valueOf(comment.getSource()).getName();
                    String linkText = "<a href=\" " + getUrlByMomentCommentSource(comment) + "\">" + sourceName + "</a>\n";
                    String commentContent = linkText + "收到新的评论: " + comment.getContent();
                    rabbitMqUtil.sendSimpleEmail(systemConfig.getEmail(), commentContent);
                } else {
                    log.error("网站没有配置通知接收的邮箱地址！");
                }
            }
        }

        // 判断被评论的用户，是否开启了评论邮件提醒
        if (StringUtils.isNotEmpty(comment.getToUserUid())) {
            UserEntity toUser = userService.getById(comment.getToUserUid());
            if (toUser.getStartEmailNotification() == SysConf.ONE) {
                R momentCommentResult = communityFeignClient.getCommentById(comment.getToUid());
                MomentCommentDto toComment;
                if (momentCommentResult.getCode() == 0) {
                    toComment = momentCommentResult.getData(new TypeReference<MomentCommentDto>(){});
                }else {
                    throw new FeignException("feign调用异常（根据id获取榜单成员评论）：失败");
                }
                sendEmailByMomentComment(comment, toUser, toComment);
            }
            // 向该用户推送消息通知
            NoticeEntity notice = new NoticeEntity();
            notice.setCreateUserUid(comment.getToUserUid());
            notice.setNoticeType(NoticeTypeEnum.MOMENT_COMMENT.getCode());
            // 设置通知类型
            if (CommentSourceEnum.RANK_MEMBER_INFO.getCode().equals(comment.getSource())) {
                notice.setBusinessType(BusinessTypeEnum.RANK_MEMBER_REPLY.getCode());
            } else if (CommentSourceEnum.ABOUT.getCode().equals(comment.getSource())) {
                notice.setBusinessType(BusinessTypeEnum.ABOUT_ME_REPLY.getCode());
            } else if (CommentSourceEnum.MESSAGE_BOARD.getCode().equals(comment.getSource())) {
                notice.setBusinessType(BusinessTypeEnum.MESSAGE_BOARD_REPLY.getCode());
            } else if (CommentSourceEnum.USER_MOMENT.getCode().equals(comment.getSource())) {
                notice.setBusinessType(BusinessTypeEnum.USER_MOMENT_REPLY.getCode());
            } else {
                throw new InsertException("消息发送失败，输入错误的评论类型");
            }
//            notice.setBusinessUid(comment.getUid());
            // 业务id改成动态id
            notice.setBusinessUid(comment.getMomentUid());
            notice.insert();

            // 被评论的人，收到小红点通知
            String redisKey = RedisConf.USER_RECEIVE_MOMENT_COMMENT_COUNT + Constants.SYMBOL_COLON + comment.getToUserUid();
            String count = redisUtil.get(redisKey);
            if (StringUtils.isNotEmpty(count)) {
                redisUtil.incrBy(redisKey, Constants.NUM_ONE);
            } else {
                redisUtil.setEx(redisKey, Constants.STR_ONE, 7, TimeUnit.DAYS);
            }

        } else {
            String tempUserUid = "";
            // 如果是一级评论，需要判断该文章或者问答是否属于用户投稿的
            if (CommentSourceEnum.USER_MOMENT.getCode().equals(comment.getSource())) {
                R momentResult = communityFeignClient.getUserMomentById(comment.getMomentUid());
                UserMomentDto userMoment;
                if (momentResult.getCode() == 0) {
                    userMoment = momentResult.getData(new TypeReference<UserMomentDto>(){});
                }else {
                    throw new FeignException("feign调用异常（根据id获取榜单成员）：失败");
                }
                if (userMoment != null) {
                    tempUserUid = userMoment.getCreateUserUid();
                    // 当是门户投稿添加的，需要向号主发送评论通知
                    NoticeEntity notice = new NoticeEntity();
                    notice.setCreateUserUid(tempUserUid);
                    notice.setFromUserUid(comment.getCreateUserUid());
                    notice.setNoticeType(NoticeTypeEnum.MOMENT_COMMENT.getCode());
                    notice.setBusinessType(BusinessTypeEnum.USER_MOMENT_COMMENT.getCode());
//                    notice.setBusinessUid(comment.getUid());
                    // 业务id改成动态id
                    notice.setBusinessUid(comment.getMomentUid());
                    notice.insert();
                }
            }

            // 如果用户投稿的文章收到评论，需要向该用户Redis收件箱中中写入一条记录
            if (StringUtils.isNotEmpty(tempUserUid)) {
                String redisKey = RedisConf.USER_RECEIVE_MOMENT_COMMENT_COUNT + Constants.SYMBOL_COLON + tempUserUid;
                String count = redisUtil.get(redisKey);
                if (StringUtils.isNotEmpty(count)) {
                    redisUtil.incrBy(redisKey, Constants.NUM_ONE);
                } else {
                    redisUtil.setEx(redisKey, Constants.STR_ONE, 7, TimeUnit.DAYS);
                }
            }
        }
        return true;
    }

    @Override
    public boolean sendNoticeByPayOrder(PayOrderDto payOrder) {

        // 判断是否开启邮件通知【管理员邮箱通知】
        SystemConfigDto systemConfig = systemConfigUtil.getSystemConfig();
        if (systemConfig != null && OpenStatusEnum.OPEN.equals(systemConfig.getStartEmailNotification())) {
            if (StringUtils.isNotEmpty(systemConfig.getEmail())) {
                String commentContent = "\"" + payOrder.getResourceTitle() + "\"" + "收到新的报名订单: " + payOrder.getOrderNo() + "，申请人: " + payOrder.getApplyUserName()+ "。";
                rabbitMqUtil.sendSimpleEmail(systemConfig.getEmail(), commentContent);
            } else {
                log.error("网站没有配置通知接收的邮箱地址！");
            }
        }
        // 获取活动发起人
        String tempUserUid = payOrder.getOrganizerUserUid();
        if(StringUtils.isEmpty(tempUserUid)){
            RankMemberEntity rankMemberEntity = rankMemberDao.getCreateUserUidByMemberUid(payOrder.getResourceUid());
            if(null != rankMemberEntity){
                tempUserUid = rankMemberEntity.getCreateUserUid();
            }
        }
        // 当是门户投稿添加的，需要向号主发送评论通知
        NoticeEntity notice = new NoticeEntity();
        notice.setCreateUserUid(tempUserUid);
        notice.setFromUserUid(payOrder.getCreateUserUid());
        notice.setNoticeType(NoticeTypeEnum.ORDER_NOTICE.getCode());
        if(OrderApplyTypeEnum.LEADER.getCode().equals(payOrder.getApplyType())) {
            notice.setBusinessType(BusinessTypeEnum.ORDER_LEADER_NOTICE.getCode());
        }else {
            notice.setBusinessType(BusinessTypeEnum.ORDER_PLAY_NOTICE.getCode());
        }
        notice.setBusinessUid(payOrder.getUid());
        notice.insert();

        // 如果用户投稿的文章收到评论，需要向该用户Redis收件箱中中写入一条记录
        if (StringUtils.isNotEmpty(tempUserUid)) {
            String redisKey = RedisConf.USER_RECEIVE_ORDER_COUNT + Constants.SYMBOL_COLON + tempUserUid;
            String count = redisUtil.get(redisKey);
            if (StringUtils.isNotEmpty(count)) {
                redisUtil.incrBy(redisKey, Constants.NUM_ONE);
            } else {
                redisUtil.setEx(redisKey, Constants.STR_ONE, 7, TimeUnit.DAYS);
            }
        }
        return true;
    }

    @Override
    public boolean sendNoticeByCancelOrder(PayOrderDto payOrder) {

        // 判断是否开启邮件通知【管理员邮箱通知】
        SystemConfigDto systemConfig = systemConfigUtil.getSystemConfig();
        if (systemConfig != null && OpenStatusEnum.OPEN.equals(systemConfig.getStartEmailNotification())) {
            if (StringUtils.isNotEmpty(systemConfig.getEmail())) {
                String commentContent = "\"" + payOrder.getResourceTitle() + "\"" + "收到报名订单被取消: " + payOrder.getOrderNo() + "，取消人: " + payOrder.getUserName()+ "。";
                rabbitMqUtil.sendSimpleEmail(systemConfig.getEmail(), commentContent);
            } else {
                log.error("网站没有配置通知接收的邮箱地址！");
            }
        }

        // 给活动发起人通知
        // 获取活动发起人
        String tempUserUid = payOrder.getOrganizerUserUid();
        List<NoticeEntity> noticeList = new ArrayList<>();

        // 如果用户投稿的文章收到评论，需要向该用户Redis收件箱中中写入一条记录
        if (StringUtils.isNotEmpty(tempUserUid)) {
            // 需要向活动发起人发送通知
            NoticeEntity notice = new NoticeEntity();
            notice.setCreateUserUid(tempUserUid);
            notice.setFromUserUid(payOrder.getCreateUserUid());
            notice.setNoticeType(NoticeTypeEnum.ORDER_NOTICE.getCode());
            if(OrderApplyTypeEnum.LEADER.getCode().equals(payOrder.getApplyType())) {
                notice.setBusinessType(BusinessTypeEnum.ORDER_LEADER_CANCEL_NOTICE.getCode());
            }else {
                notice.setBusinessType(BusinessTypeEnum.ORDER_PLAY_CANCEL_NOTICE.getCode());
            }
            notice.setBusinessUid(payOrder.getUid());
            noticeList.add(notice);

            String redisKey = RedisConf.USER_RECEIVE_ORDER_COUNT + Constants.SYMBOL_COLON + tempUserUid;
            String count = redisUtil.get(redisKey);
            if (StringUtils.isNotEmpty(count)) {
                redisUtil.incrBy(redisKey, Constants.NUM_ONE);
            } else {
                redisUtil.setEx(redisKey, Constants.STR_ONE, 7, TimeUnit.DAYS);
            }
        }
        // 给报名人通知
        // 获取报名人
        String orderUserUid = payOrder.getCreateUserUid();

        // 如果用户投稿的文章收到评论，需要向该用户Redis收件箱中中写入一条记录
        if (StringUtils.isNotEmpty(orderUserUid) && !orderUserUid.equals(tempUserUid)) {
            // 需要向报名人发送通知
            NoticeEntity notice2 = new NoticeEntity();
            notice2.setCreateUserUid(orderUserUid);
            notice2.setFromUserUid(payOrder.getOperateUserUid());
            notice2.setNoticeType(NoticeTypeEnum.ORDER_NOTICE.getCode());
            if(OrderApplyTypeEnum.LEADER.getCode().equals(payOrder.getApplyType())) {
                notice2.setBusinessType(BusinessTypeEnum.MY_ORDER_LEADER_CANCEL_NOTICE.getCode());
            }else {
                notice2.setBusinessType(BusinessTypeEnum.MY_ORDER_PLAY_CANCEL_NOTICE.getCode());
            }
            notice2.setBusinessUid(payOrder.getUid());
            noticeList.add(notice2);

            String redisKey = RedisConf.USER_RECEIVE_ORDER_COUNT + Constants.SYMBOL_COLON + orderUserUid;
            String count = redisUtil.get(redisKey);
            if (StringUtils.isNotEmpty(count)) {
                redisUtil.incrBy(redisKey, Constants.NUM_ONE);
            } else {
                redisUtil.setEx(redisKey, Constants.STR_ONE, 7, TimeUnit.DAYS);
            }
        }
        if (ListUtils.isNotEmpty(noticeList)) {
            return this.saveBatch(noticeList);
        }
        return true;
    }

    /**
     * 发送评论邮件
     *
     * @param comment
     * @param toUser
     * @param toComment
     */
    private void sendEmailByMemberComment(MemberCommentDto comment, UserEntity toUser, MemberCommentDto toComment) {
        if (toComment != null && StringUtils.isNotEmpty(toComment.getContent())) {
            Map<String, String> map = new HashMap<>();
            map.put(SysConf.EMAIL, toUser.getEmail());
            map.put(SysConf.TEXT, comment.getContent());
            map.put(SysConf.TO_TEXT, toComment.getContent());

            if (comment.getUser() != null) {
                map.put(SysConf.NICKNAME, comment.getUser().getNickname());
            }
            map.put(SysConf.TO_NICKNAME, toUser.getNickname());
            map.put(SysConf.USER_UID, toUser.getUid());
            // 获取评论跳转的链接
            String commentSource = toComment.getSource();
            String url = new String();
            switch (commentSource) {
                case "ABOUT": {
                    url = dataWebsiteUrl + "about";
                }
                break;
                case "RANK_MEMBER_INFO": {
                    url = dataWebsiteUrl + "info?memberUid=" + toComment.getMemberUid();
                }
                break;
                case "MESSAGE_BOARD": {
                    url = dataWebsiteUrl + "messageBoard";
                }
                break;
                default: {
                    log.error("跳转到其它链接");
                }
            }
            map.put(SysConf.URL, url);
            // 发送评论邮件
            rabbitMqUtil.sendCommentEmail(map);
        }
    }

    /**
     * 通过评论类型跳转到对应的页面
     *
     * @param comment
     * @return
     */
    private String getUrlByMemberCommentSource(MemberCommentDto comment) {
        String linkUrl = new String();
        String commentSource = comment.getSource();
        switch (commentSource) {
            case "ABOUT": {
                linkUrl = dataWebsiteUrl + "about";
            }
            break;
            case "RANK_MEMBER_INFO": {
                linkUrl = dataWebsiteUrl + "info?memberUid=" + comment.getMemberUid();
            }
            break;
            case "MESSAGE_BOARD": {
                linkUrl = dataWebsiteUrl + "messageBoard";
            }
            break;
            default: {
                linkUrl = dataWebsiteUrl;
                log.error("跳转到其它链接");
            }
        }
        return linkUrl;
    }

    /**
     * 发送评论邮件
     *
     * @param comment
     * @param toUser
     * @param toComment
     */
    private void sendEmailByMomentComment(MomentCommentDto comment, UserEntity toUser, MomentCommentDto toComment) {
        if (toComment != null && StringUtils.isNotEmpty(toComment.getContent())) {
            Map<String, String> map = new HashMap<>();
            map.put(SysConf.EMAIL, toUser.getEmail());
            map.put(SysConf.TEXT, comment.getContent());
            map.put(SysConf.TO_TEXT, toComment.getContent());

            if (comment.getUser() != null) {
                map.put(SysConf.NICKNAME, comment.getUser().getNickname());
            }
            map.put(SysConf.TO_NICKNAME, toUser.getNickname());
            map.put(SysConf.USER_UID, toUser.getUid());
            // 获取评论跳转的链接
            String commentSource = toComment.getSource();
            String url = new String();
            switch (commentSource) {
                case "ABOUT": {
                    url = dataWebsiteUrl + "about";
                }
                break;
                case "USER_MOMENT": {
                    url = dataWebsiteUrl + "info?momentUid=" + toComment.getMomentUid();
                }
                break;
                case "MESSAGE_BOARD": {
                    url = dataWebsiteUrl + "messageBoard";
                }
                break;
                default: {
                    log.error("跳转到其它链接");
                }
            }
            map.put(SysConf.URL, url);
            // 发送评论邮件
            rabbitMqUtil.sendCommentEmail(map);
        }
    }

    /**
     * 通过评论类型跳转到对应的页面
     *
     * @param comment
     * @return
     */
    private String getUrlByMomentCommentSource(MomentCommentDto comment) {
        String linkUrl = new String();
        String commentSource = comment.getSource();
        switch (commentSource) {
            case "ABOUT": {
                linkUrl = dataWebsiteUrl + "about";
            }
            break;
            case "USER_MOMENT": {
                linkUrl = dataWebsiteUrl + "info?momentUid=" + comment.getMomentUid();
            }
            break;
            case "MESSAGE_BOARD": {
                linkUrl = dataWebsiteUrl + "messageBoard";
            }
            break;
            default: {
                linkUrl = dataWebsiteUrl;
                log.error("跳转到其它链接");
            }
        }
        return linkUrl;
    }
}